package com.wavehi.web.homework.fifth;

import com.wavehi.pojo.User;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @Author WaveHi
 * @Date 17/9/2021 下午 9:13
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Demonstrate the use of EL
 */
@WebServlet("/elDemoServlet")
public class ELDemoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取数据
        User user = new User(1L, "Betty", "rierqo");
        ArrayList<String> list = new ArrayList<>(16);
        HashMap<String, Integer> map = new HashMap<>(16);
        String[] strs = {"Hello!", "Yes!", "No!", "Wow!"};
        list.add("1232");
        list.add("34930");
        map.put("age", 12);
        //设置域对象的数据
        req.setAttribute("user", user);
        req.setAttribute("list", list);
        req.setAttribute("map", map);
        req.setAttribute("strs", strs);
        //获取请求转发对象
        RequestDispatcher dis = req.getRequestDispatcher("page/homework/homework05.jsp");
        //转发
        dis.forward(req, resp);
    }
}
